(function () {
    "use strict";

    angular.module('core').factory('tarefaService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        return {
            get: function (id) {
                let args = { id: id };
                let deferred = $q.defer();
                $http.post('/tarefa/get', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getAll: function (args) {
                let deferred = $q.defer();
                $http.post('/tarefa/getall', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            count: function (args) {
                let deferred = $q.defer();
                $http.post('/tarefa/count', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getFullTree: function (id) {
                let args = { id: id };
                let deferred = $q.defer();
                $http.post('/tarefa/getFullTree', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getDistinctStatus: function (args) {
                let deferred = $q.defer();
                $http.post('/tarefa/getDistinctStatus', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            prepareNew: function () {
                let deferred = $q.defer();
                $http.post('/tarefa/prepareNew')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            prepare: function (item) {
                let deferred = $q.defer();
                $http.post('/tarefa/prepare', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            save: function (item) {
                let deferred = $q.defer();
                $http.post('/tarefa/save', item)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            delete: function (id) {
                let args = { id: id };
                let deferred = $q.defer();
                $http.post('/tarefa/delete', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
        };
    }

})();


